// 线段树-数学(区间方差), 与数学结合的线段树问题需要先进行数学推导
// d = (x1 - A) * (x1 - A) + ...
// x1^2 + A^2 - 2 * A * x1 ...
// x1^2 + x2 ^2 + ... + n * A^2 - 2 * A *(x1 + x2 + ...)
// 平方和 / n -  A^2
// 因此只需要知道平方和和平均数即可推导出方差

#include <iostream>
using namespace std;
typedef long long ll;
#define lc p << 1
#define rc p << 1 | 1
const int N = 1e5 + 10, mod = 1e9 + 7;
;
ll a[N];

struct node
{
    int l, r;
    ll s1, s2; // 平方和、区间和
} tr[N << 2];

void pushup(node &p, node &l, node &r)
{
    p.s1 = (l.s1 + r.s1) % mod;
    p.s2 = (l.s2 + r.s2) % mod;
}

void build(int p, int l, int r)
{
    tr[p] = {l, r, a[l] * a[l] % mod, a[l]};
    if (l == r)
        return;
    int mid = (l + r) >> 1;
    build(lc, l, mid);
    build(rc, mid + 1, r);
    pushup(tr[p], tr[lc], tr[rc]);
}

void modify(int p, int x, ll k)
{
    int l = tr[p].l, r = tr[p].r;
    if (x == l && r == x)
    {
        tr[p].s1 = (k * k) % mod;
        tr[p].s2 = k;
        return;
    }
    int mid = (l + r) >> 1;
    if (x <= mid)
        modify(lc, x, k);
    else
        modify(rc, x, k);
    pushup(tr[p], tr[lc], tr[rc]);
}

// 查询方差, 无法直接得到, 需要返回[x, y]的平方和和区间和
node query(int p, int x, int y)
{
    int l = tr[p].l, r = tr[p].r;
    if (x <= l && r <= y)
        return tr[p];
    int mid = (l + r) >> 1;
    if (y <= mid)
        return query(lc, x, y);
    if (x > mid)
        return query(rc, x, y);
    node ret, L = query(lc, x, y), R = query(rc, x, y);
    pushup(ret, L, R);
    return ret;
}

ll qpow(ll a, ll b, ll mod)
{
    ll ret = 1;
    while (b)
    {
        if (b & 1)
            ret = ret * a % mod;
        a = a * a % mod;
        b >>= 1;
    }
    return ret;
}

int main()
{
    int n, m;
    cin >> n >> m;
    for (int i = 1; i <= n; i++)
        cin >> a[i];
    build(1, 1, n);
    while (m--)
    {
        int op, x, y;
        cin >> op >> x >> y;
        if (op == 1)
        {
            modify(1, x, y);
        }
        else
        {
            node t = query(1, x, y);
            ll s1 = t.s1, s2 = t.s2;
            ll len = (y - x + 1);
            ll inv = qpow(len, mod - 2, mod);
            ll A = s2 * inv % mod;
            ll ret = s1 * inv % mod - A * A % mod;
            cout << (ret % mod + mod) % mod << endl;
        }
    }
    return 0;
}